﻿using ArtMath.Attribute;
using ArtMath.Component.Interface;
using ArtMath.Component.Polygon;
using ArtMath.Core.Data;
using ArtMath.Setting;
using System;
using System.ComponentModel;
using System.Drawing;

namespace ArtMath.Component.Point
{
    /// <summary>
    /// 图形中心基类
    /// </summary>
    [Serializable]
    public abstract class ShapeCenterBase : ConstructedPointBase
    {
        public ShapeCenterBase(SketchPad pad, string name, LineBase shape, bool addToList = true) : base(pad, name, ToolTypeName.zx, addToList)
        {
            OutHosts = new LineBase[1];
            Shape = shape;
            OutlineColor = Settings.Instance.ShapeCenterPointOutlineColor;
            FillColor = Settings.Instance.ShapeCenterFillColor;
        }
        [DefaultValue(typeof(Color), "255, 192, 0")]
        public override Color OutlineColor
        {
            get
            {
                return base.OutlineColor;
            }

            set
            {
                base.OutlineColor = value;
            }
        }
        [DefaultValue(typeof(Color), "255, 244, 231")]
        public override Color FillColor
        {
            get
            {
                return base.FillColor;
            }

            set
            {
                base.FillColor = value;
            }
        }
        [MultilingualCategory("Structure"), MultilingualDisplayName("Shape")]
        public LineBase Shape
        {
            get { return OutHosts[0]; }
            set { SetLine(0, value); }
        }
        public override PointD GetNewLocationAfterOutHostChanged(bool getXY = false)
        {
            ICenter ic = Shape as ICenter;
            if (ic != null)
            {
                return getXY ? ic.NewCenter : ic.NewPCenter;
            }
            else
            {
                ArbitraryPolygon ap = Shape as ArbitraryPolygon;
                if (ap != null && ap.IsRegularPolygon)
                {
                    return getXY ? ap.NewBaryCenter : ap.NewPBaryCenter;
                }
            }
            return base.GetNewLocationAfterOutHostChanged(getXY);
        }
        public override void ConvertType(ToolTypeName targetType)
        {
            if (targetType != ToolType) return;
            ShapeCenterBase targetPoint = null;
            SimulateDeleted(() =>
            {
                if (Pad.CoordinateType == CoordinateSystemType.PolarCoordinate)
                {
                    targetPoint = new PShapeCenter(Pad, Name, Shape, false);
                }
                else
                {
                    targetPoint = new RShapeCenter(Pad, Name, Shape, false);
                }
            });
            afterGenerateNewType(targetPoint);
        }
    }
}
